package com.zlq.javaWeb3.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY;

@WebServlet(urlPatterns = "/jsLoginController")
public class JsLoginController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String token = (String) req.getAttribute("codes");
        req.getSession().removeAttribute("codes");

        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");

        String name = req.getParameter("name");
        String password = req.getParameter("password");
        String code = req.getParameter("code");
        if (token != null && token.equalsIgnoreCase(code)) {

            req.setAttribute("name",name);


//            System.out.println(i);
            req.getRequestDispatcher("company.jsp").forward(req, resp);
        } else {
            req.getRequestDispatcher("/jsLogin/index.jsp").forward(req, resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
